<template>
  <el-dialog :show-close="false" v-if="windowOpen" append-to-body :before-close="closeWindow" :visible.sync="windowOpen" width="600px" top="15vh">
    <template #title>
      <span style="display:flex;justify-content: center;">{{ windowData.number }}</span>
    </template>
    <div id="view-box">
      <!--  图源区域  -->
      <div class="main-container">
        <image-zoom ref="ImageIndex"
                    :imgUrl="windowData.imageUrl"
                    :mode="1"/>
        <span v-if="currentIndex !== 0" class="el-icon-caret-left left-icon-box icon-box" @click="toLast"/>
        <span v-if="currentIndex !== indexMax" class="el-icon-caret-right right-icon-box icon-box" @click="toNext"/>
      </div>
    </div>
  </el-dialog>
</template>

<script>
import imageZoom from "@/components/mgWindow/imageZoom.vue";

export default {
  name: 'viewWindow',
  props: ['indexMax'],
  components: {imageZoom},
  data() {
    return {
      windowOpen: false,
      windowData: {},
      currentIndex: 0,
    }
  },
  methods: {
    reset() {
      this.$nextTick(() => {
        this.$refs.ImageIndex.initImg()
      })
    },
    /**
     * 打开窗口
     * @param index 当前下标
     * @param windowData 当前窗口数据
     */
    openWindow(index, windowData) {
      this.windowOpen = true
      this.flashData(index, windowData)
    },
    toLast() {
      this.$emit('toLast')
    },
    toNext() {
      this.$emit('toNext')
    },
    /**
     * 刷新数据
     * @param index 当前下标
     * @param windowData 当前窗口数据
     */
    flashData(index, windowData) {
      this.windowData = windowData
      this.currentIndex = index
      this.reset()
    },
    /**
     * 关闭窗口
     */
    closeWindow() {
      this.windowOpen = false
    }
  }
}

</script>
<style scoped lang="scss">
#view-box {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-content: center;

  .main-container {
    padding: 0;
    height: 650px;
    width: 600px;
    border-radius: 5px;
    overflow: hidden;
    border: 1px solid gainsboro;
    box-sizing: border-box;
    background-color: #f6f6f6;
    position: relative;

    .icon-box {
      position: absolute;
      top: calc(50% - 25px);
      width: 50px;
      height: 50px;
      border: 1px gainsboro solid;
      border-radius: 50%;
      background: #ffffff;
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: xx-large;
      opacity: 0.2;
      z-index: 999999999;
      transition: all 0.3s ease;
    }

    .icon-box:hover {
      opacity: 0.6;
      cursor: pointer;
    }

    .left-icon-box {
      left: 20px;
    }

    .right-icon-box {
      right: 20px;
    }
  }
}
</style>